package com.surface.hao.util;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Toolkit;

/**
 * Swing�Ĺ�����
 * @author songhao
 */
public class SwingUtils {
	
	/**
	 * ���ÿؼ�����Ļ�����м�
	 * @param component
	 * @param width
	 * @param height
	 */
	public static void setLocationCenter(Component component,int width,int  height) {
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension compSize = component.getSize();
		
		if (compSize.height > screenSize.height) {
			compSize.height = screenSize.height;
		}
		if (compSize.width > screenSize.width) {
			compSize.width = screenSize.width;
		}
		component.setSize(width, height);
		//���ÿؼ���λ��
		component.setLocation((screenSize.width - compSize.width) / 2 - width / 2,
				(screenSize.height - compSize.height) / 2 - height / 2);
	}
}
